﻿using Dapper;
using HR.IServices.PengIService;
using HR.Models.PengModels;
using System.Data.SqlClient;

namespace HR.Services.PengService
{
    public class First_kindServices : IFirst_kindServices
    {
        private readonly IConfiguration conf;
        private readonly string? conStr;

        public First_kindServices(IConfiguration conf)
        {
            this.conf = conf;
            conStr = this.conf["ConnectionStrings"];
        }
        public Task<int> Add(First_kind first_Kind)
        {
            return Task.Run(() =>
            {
                using (SqlConnection con = new SqlConnection(conStr))
                {
                    return con.Execute($"insert into config_file_first_kind(first_kind_id, first_kind_name, first_kind_salary_id, first_kind_sale_id) values('{first_Kind.First_kind_id}','{first_Kind.First_kind_name}','{first_Kind.First_kind_salary_id}','{first_Kind.First_kind_sale_id}')");
                }
            });
        }

        public Task<int> Delete(int ffk_id)
        {
            return Task.Run(() =>
            {
               using (SqlConnection con = new SqlConnection(conStr))
               {
                  return con.Execute($"delete from config_file_first_kind where ffk_id='{ffk_id}'");
               }
            });
        
        }

        public Task<List<First_kind>> FindAll()
        {
           return Task.Run(() => 
            {
                using (SqlConnection con = new SqlConnection(conStr))
                {
                    return con.Query<First_kind>($"select * from config_file_first_kind").ToList();
                }
            });
        }

        public Task<int> Update(First_kind first_Kind)
        {
            return Task.Run(() =>
            {
                using (SqlConnection con = new SqlConnection(conStr))
                {
                    return con.Execute($" update config_file_first_kind set first_kind_id = '{first_Kind.First_kind_id}', first_kind_name = '{first_Kind.First_kind_name}', first_kind_salary_id = '{first_Kind.First_kind_salary_id}', first_kind_sale_id = '{first_Kind.First_kind_sale_id}' where first_kind_id = '{first_Kind.First_kind_id}'");
                }
            });
        }
    }
}
